package de.breitbeil.jbooking.ui.view.tablecellrenderer;

import java.awt.Component;

import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

import de.breitbeil.jbooking.domain.Booking;
import de.breitbeil.jbooking.util.StringUtils;

public class BookingFromToTableCellRenderer extends DefaultTableCellRenderer {

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        
        if(value instanceof Booking && value != null) {
            Booking booking = (Booking) value;
            
            String fromString = StringUtils.dateToString(booking.getFrom());
            String toString = StringUtils.dateToString(booking.getTo());
            
            if(StringUtils.hasText(fromString) || StringUtils.hasText(toString)) {
                setText(fromString + " - " + toString);
            }
            else {
                setText("");
            }
        }
        
        return this;
    }
}
